﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using CLEXA.DataContracts;
using CLEXA.SurfaceClient.Functions;

namespace CLEXA.SurfaceClient.ViewModel
{
    public class DatabaseDeleteVM : VMBase
    {
        private readonly IDatabaseDelete facade;
        private readonly int databaseId;
        private readonly int userId;
        private readonly string connectionString;
        private readonly RelayCommand delete;
        private readonly RelayCommand cancel;

        public string ConnectionString
        {
            get { return connectionString; }
        }

        public ICommand Delete
        {
            get { return delete; }
        }

        public ICommand Cancel
        {
            get { return cancel; }
        }

        public DatabaseDeleteVM(IDatabaseDelete facade, int databaseId)
        {
            this.facade = facade;
            this.databaseId = databaseId;
            this.userId = facade.Databases[databaseId].UserId;
            this.connectionString = facade.Databases[databaseId].ConnectionString;
            this.delete = new RelayCommand(DoDelete);
            this.cancel = new RelayCommand(DoCancel);
        }

        private void DoDelete()
        {
            this.facade.DeleteDatabase(databaseId);
            this.facade.ClosePopUp();
        }


        private void DoCancel()
        {
            this.facade.ClosePopUp();
        }
    }
}
